package pku.ss.movieSystem.services.impl;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import pku.ss.movieSystem.services.IBasicService;
import daos.Hall;
import daos.HallDAO;
import daos.Session;
import daos.SessionDAO;

public class BasicService implements IBasicService {

	private HallDAO hallDao;
	private SessionDAO sessionDao;
	
	public void addHall(Hall hall) {
		hallDao.save(hall);
	}
	
	public String getHallsInfo() {
		List<Hall> halls = hallDao.findAll();
		JSONObject jsonObj = new JSONObject();
		JSONArray jsonArray = new JSONArray();
		
		for(Hall hall : halls) {
			jsonObj.put("hallId", hall.getHallId());
			jsonObj.put("hallName", hall.getHallName());
			jsonObj.put("hallSeats", hall.getHallSeats());
			jsonObj.put("hallDesc", hall.getHallDesc());
			
			jsonArray.add(jsonObj);
		}
		return jsonArray.toString();
	}
	
	public Hall getHallById(Integer hallId) {
		return hallDao.findById(hallId);
	}
	
	public void addMovieSession(Session session) {
		this.sessionDao.save(session);
	}
	
	public void deleteMovieSession(Integer sessionId) {
		this.sessionDao.deleteById(sessionId);
	}
	
	public void updateMovieSession(Session session) {
		this.sessionDao.updateSession(session);
	}
	
	public void setHallDao(HallDAO hallDao) {
		this.hallDao = hallDao;
	}
	
	public HallDAO getHallDao() {
		return this.hallDao;
	}
	
	public void setSessionDao(SessionDAO sessionDao) {
		this.sessionDao = sessionDao;
	}
	
	public SessionDAO getSessionDao() {
		return this.sessionDao;
	}
}
